/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tbv_comunaDAOImpl implements orm.dao.Tbv_comunaDAO {
	public Tbv_comuna loadTbv_comunaByORMID(int co_id_comuna) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_comunaByORMID(session, co_id_comuna);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna getTbv_comunaByORMID(int co_id_comuna) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_comunaByORMID(session, co_id_comuna);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna loadTbv_comunaByORMID(int co_id_comuna, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_comunaByORMID(session, co_id_comuna, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna getTbv_comunaByORMID(int co_id_comuna, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_comunaByORMID(session, co_id_comuna, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna loadTbv_comunaByORMID(PersistentSession session, int co_id_comuna) throws PersistentException {
		try {
			return (Tbv_comuna) session.load(orm.Tbv_comuna.class, new Integer(co_id_comuna));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna getTbv_comunaByORMID(PersistentSession session, int co_id_comuna) throws PersistentException {
		try {
			return (Tbv_comuna) session.get(orm.Tbv_comuna.class, new Integer(co_id_comuna));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna loadTbv_comunaByORMID(PersistentSession session, int co_id_comuna, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_comuna) session.load(orm.Tbv_comuna.class, new Integer(co_id_comuna), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna getTbv_comunaByORMID(PersistentSession session, int co_id_comuna, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_comuna) session.get(orm.Tbv_comuna.class, new Integer(co_id_comuna), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna[] listTbv_comunaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_comunaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna[] listTbv_comunaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_comunaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna[] listTbv_comunaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_comuna as Tbv_comuna");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tbv_comuna[]) list.toArray(new Tbv_comuna[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna[] listTbv_comunaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_comuna as Tbv_comuna");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tbv_comuna[]) list.toArray(new Tbv_comuna[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna loadTbv_comunaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_comunaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna loadTbv_comunaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_comunaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna loadTbv_comunaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tbv_comuna[] tbv_comunas = listTbv_comunaByQuery(session, condition, orderBy);
		if (tbv_comunas != null && tbv_comunas.length > 0)
			return tbv_comunas[0];
		else
			return null;
	}
	
	public Tbv_comuna loadTbv_comunaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tbv_comuna[] tbv_comunas = listTbv_comunaByQuery(session, condition, orderBy, lockMode);
		if (tbv_comunas != null && tbv_comunas.length > 0)
			return tbv_comunas[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTbv_comunaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_comunaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_comunaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_comunaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_comunaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_comuna as Tbv_comuna");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_comunaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_comuna as Tbv_comuna");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna createTbv_comuna() {
		return new orm.Tbv_comuna();
	}
	
	public boolean save(orm.Tbv_comuna tbv_comuna) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().saveObject(tbv_comuna);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tbv_comuna tbv_comuna) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().deleteObject(tbv_comuna);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_comuna tbv_comuna)throws PersistentException {
		try {
			if(tbv_comuna.getTbv_provinciapr_id_provincia() != null) {
				tbv_comuna.getTbv_provinciapr_id_provincia().tbv_comuna.remove(tbv_comuna);
			}
			
			orm.Tbv_maquina[] lTbv_maquinas = tbv_comuna.tbv_maquina.toArray();
			for(int i = 0; i < lTbv_maquinas.length; i++) {
				lTbv_maquinas[i].setTbv_comunaco_id_comuna(null);
			}
			return delete(tbv_comuna);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_comuna tbv_comuna, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(tbv_comuna.getTbv_provinciapr_id_provincia() != null) {
				tbv_comuna.getTbv_provinciapr_id_provincia().tbv_comuna.remove(tbv_comuna);
			}
			
			orm.Tbv_maquina[] lTbv_maquinas = tbv_comuna.tbv_maquina.toArray();
			for(int i = 0; i < lTbv_maquinas.length; i++) {
				lTbv_maquinas[i].setTbv_comunaco_id_comuna(null);
			}
			try {
				session.delete(tbv_comuna);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tbv_comuna tbv_comuna) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().refresh(tbv_comuna);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tbv_comuna tbv_comuna) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().evict(tbv_comuna);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_comuna loadTbv_comunaByCriteria(Tbv_comunaCriteria tbv_comunaCriteria) {
		Tbv_comuna[] tbv_comunas = listTbv_comunaByCriteria(tbv_comunaCriteria);
		if(tbv_comunas == null || tbv_comunas.length == 0) {
			return null;
		}
		return tbv_comunas[0];
	}
	
	public Tbv_comuna[] listTbv_comunaByCriteria(Tbv_comunaCriteria tbv_comunaCriteria) {
		return tbv_comunaCriteria.listTbv_comuna();
	}
}
